<template>
    <div class="container">
        <div class="login-wrapper">
            <div class="header">Sign up</div>
            <div class="form-wrapper">
                <div>
                    <input type="text" name="username" id="username" v-model="username" placeholder="登录账号"
                        class="input-item">
                    <input type="password" name="password" v-model="password" id="password" placeholder="登录密码"
                        class="input-item">
                    <input type="password" name="password2" v-model="password2" id="password2" placeholder="确认密码"
                        class="input-item">

                    <div class="member-register">
                        <label class="member-label">
                            <input type="checkbox" v-model="isMember" class="member-checkbox">
                            <span>会员注册</span>
                        </label>
                    </div>

                    <input class="btn" type="submit" @click="check()" value="注册" />
                </div>
            </div>
            <div class="msg">
                已有账户？<a href='login.jsp' style="font-weight: bold;">去登录</a>
            </div>
        </div>
    </div>
</template>

<script>
import axios from 'axios';
import { AddUser } from '@/api/admin/User';
export default {
    data() {
        return {
            username: '',
            password: '',
            password2: '',
            isMember: false
        }
    },
    methods: {
        check() {
            if (this.username == "") {
                alert("用户名不能为空！");
            }
            else if (this.password == "") {
                alert("密码不能为空！");
            }
            else if (this.password2 != this.password) {
                alert("密码输入不一致！");
            } else {
                const user = {
                    uid: this.isMember ? 1 : 0,
                    name: this.username,
                    password: this.password
                }
                AddUser(JSON.stringify(user))
                    .then(res => {
                        console.log(res.data);
                        if (res.msg == null) {
                            alert('添加成功您的账号为' + res.data.data)
                            this.$router.push(-1)
                        } else {
                            alert(res.msg)
                        }
                    }
                    ).catch(error => {
                        console.log(error.response)
                    })
            }
        }
    }
}

</script>

<style scoped>
* {
    padding: 0;
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    letter-spacing: .05em;
}

html {
    height: 100%;
}

body {
    height: 100%;
}

.container {
    height: 100vh;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(1200px 600px at 20% 10%, rgba(255, 255, 255, 0.08), transparent 60%),
        radial-gradient(1000px 500px at 80% 90%, rgba(0, 0, 0, 0.15), transparent 60%),
        linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-size: cover;
}

.login-wrapper {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(14px);
    width: 100%;
    max-width: 380px;
    padding: 36px 28px;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(50, 50, 93, 0.15), 0 8px 16px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.35);
    animation: fadeIn .35s ease;
}

.login-wrapper .header {
    font-size: 28px;
    font-weight: 800;
    text-align: center;
    margin-bottom: 24px;
    background: linear-gradient(135deg, #5b6ee1 0%, #8a5bd2 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-wrapper .form-wrapper .input-item {
    display: block;
    width: 100%;
    margin-bottom: 16px;
    border: 1.5px solid rgba(102, 126, 234, 0.28);
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
    background: rgba(255, 255, 255, 0.96);
}

.login-wrapper .form-wrapper .input-item:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.18);
}

.member-register {
    margin: 12px 0 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.member-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 14px;
    color: #555;
}

.member-radio,
.member-checkbox {
    margin-right: 8px;
    width: 16px;
    height: 16px;
    accent-color: #a6c1ee;
}

.login-wrapper .form-wrapper .btn {
    text-align: center;
    padding: 12px 16px;
    margin-top: 16px;
    width: 100%;
    background-image: linear-gradient(135deg, #6a7ae6 0%, #8a5bd2 100%);
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.22s ease, box-shadow 0.22s ease, background 0.22s ease;
    box-shadow: 0 8px 18px rgba(107, 122, 230, 0.35);
}

.login-wrapper .form-wrapper .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 26px rgba(107, 122, 230, 0.45);
}

.login-wrapper .msg {
    text-align: center;
    margin-top: 12px;
    color: #666;
    font-size: 14px;
}

.login-wrapper .msg a {
    text-decoration: none;
    color: #5b6ee1;
    font-weight: 600;
    transition: color 0.2s;
}

.login-wrapper .msg a:hover {
    color: #4f46e5;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
</style>